package cn.laixueit.mapper;

import cn.laixueit.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface UserMapper {

    @Select("select * from user")
    @Results(
            id = "userMap",
            value = {
                    @Result(id = true,property = "id",column = "id"),
                    @Result(property = "username" ,column = "user_name"),
                    @Result(property = "gender",column = "gender")
            }
    )
    public List<User> findAll();

    @Select("select * from user where id =#{id}")
    @ResultMap(value = {"userMap"})
    public User findById(Integer id);

    @Insert("insert into user(user_name) values(#{username})")
    public int addUser(User user);

    @Update("update user set user_name=#{username} where id =#{id}")
    public int updateUser(User user);

    @Delete("delete from user where id =#{id}")
    public int deleteUser (Integer id);

    @Select("select * from user limit #{startPage},#{pageSize}")
    public List<User> findPage(Map<String,Integer> map);

    @Select("select count(1) from user")
    public int count();

}
